﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wf5.Engine.Common;
using Wf5.Engine.Business;

using FCDB.Entity;

namespace Wf5.Engine.Core
{
    /// <summary>
    /// 与分支节点
    /// </summary>
    internal class AndSplitNode : NodeBase, ICompleteAutomaticlly
    {
        internal AndSplitNode(ActivityEntity activity)
            : base(activity)
        {

        }

        internal override void AfterActivityInstanceObjectCreated()
        {
            base.ActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.AndSplit;

        }

        #region ICompleteAutomaticlly 成员
        public GatewayExecutedResult CompleteAutomaticlly(WfProcessInstance processInstance,
            Guid transitionGUID,
            WfActivityInstance fromActivityInstance, 
            ActivityResource activityResource
            )
        {

            //插入实例数据
            var toActivityInstance = base.CreateActivityInstanceObject(processInstance, activityResource.LogonUser);
            base.InsertActivityInstance(toActivityInstance 
                );

            base.CompleteActivityInstance(toActivityInstance.ID,
                activityResource
                );

            base.SyncActivityInstanceObjectState(NodeStateEnum.Completed);

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                TransitionTypeEnum.Forward,
                TransitionFlyingTypeEnum.NotFlying,
                activityResource.LogonUser
                );

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);
            return result;
        }

        #endregion
    }
}
